Hệ thống quản lý phòng khám trực tuyến bằng PHP

1 <?php
2
3 // Data functions (insert, update, delete, form)
for table patients
4
5 // This script and data application were generated
by AppGini 5.62
6 // Download AppGini
for free from https://bigprof.com/appgini/download/
7
8 function patients_insert(){
9     
global $Translation;
10
11     
// mm: can member insert record?
12     $arrPerm=getTablePermissions(
'patients');
13     
if(!$arrPerm[1]){
14         
return false;
15     }
16
17     $data[
'last_name'] = makeSafe($_REQUEST['last_name']);
18         
if($data['last_name'] == empty_lookup_value){ $data['last_name'] = ''; }
19     $data[
'first_name'] = makeSafe($_REQUEST['first_name']);
20         
if($data['first_name'] == empty_lookup_value){ $data['first_name'] = ''; }
21     $data[
'gender'] = makeSafe($_REQUEST['gender']);
22         
if($data['gender'] == empty_lookup_value){ $data['gender'] = ''; }
23     $data[
'sexual_orientation'] = makeSafe($_REQUEST['sexual_orientation']);
24         
if($data['sexual_orientation'] == empty_lookup_value){ $data['sexual_orientation'] = ''; }
25     $data[
'birth_date'] = intval($_REQUEST['birth_dateYear']) . '-' . intval($_REQUEST['birth_dateMonth']) . '-' . intval($_REQUEST['birth_dateDay']);
26     $data[
'birth_date'] = parseMySQLDate($data['birth_date'], '');
27     $data[
'address'] = br2nl(makeSafe($_REQUEST['address']));
28     $data[
'city'] = makeSafe($_REQUEST['city']);
29         
if($data['city'] == empty_lookup_value){ $data['city'] = ''; }
30     $data[
'state'] = makeSafe($_REQUEST['state']);
31         
if($data['state'] == empty_lookup_value){ $data['state'] = ''; }
32     $data[
'zip'] = makeSafe($_REQUEST['zip']);
33         
if($data['zip'] == empty_lookup_value){ $data['zip'] = ''; }
34     $data[
'home_phone'] = makeSafe($_REQUEST['home_phone']);
35         
if($data['home_phone'] == empty_lookup_value){ $data['home_phone'] = ''; }
36     $data[
'work_phone'] = makeSafe($_REQUEST['work_phone']);
37         
if($data['work_phone'] == empty_lookup_value){ $data['work_phone'] = ''; }
38     $data[
'mobile'] = makeSafe($_REQUEST['mobile']);
39         
if($data['mobile'] == empty_lookup_value){ $data['mobile'] = ''; }
40     $data[
'tobacco_usage'] = makeSafe($_REQUEST['tobacco_usage']);
41         
if($data['tobacco_usage'] == empty_lookup_value){ $data['tobacco_usage'] = ''; }
42     $data[
'alcohol_intake'] = makeSafe($_REQUEST['alcohol_intake']);
43         
if($data['alcohol_intake'] == empty_lookup_value){ $data['alcohol_intake'] = ''; }
44     $data[
'history'] = makeSafe($_REQUEST['history']);
45         
if($data['history'] == empty_lookup_value){ $data['history'] = ''; }
46     $data[
'surgical_history'] = br2nl(makeSafe($_REQUEST['surgical_history']));
47     $data[
'obstetric_history'] = br2nl(makeSafe($_REQUEST['obstetric_history']));
48     $data[
'genetic_diseases'] = br2nl(makeSafe($_REQUEST['genetic_diseases']));
49     $data[
'contact_person'] = makeSafe($_REQUEST['contact_person']);
50         
if($data['contact_person'] == empty_lookup_value){ $data['contact_person'] = ''; }
51     $data[
'other_details'] = br2nl(makeSafe($_REQUEST['other_details']));
52     $data[
'comments'] = makeSafe($_REQUEST['comments']);
53         
if($data['comments'] == empty_lookup_value){ $data['comments'] = ''; }
54     $data[
'filed'] = parseCode('<%%creationDateTime%%>', true, true);
55     $data[
'image'] = PrepareUploadedFile('image', 1024000,'jpg|jpeg|gif|png', false, '');
56     
if($data['image']) createThumbnail($data['image'], getThumbnailSpecs('patients', 'image', 'tv'));
57     
if($data['image']) createThumbnail($data['image'], getThumbnailSpecs('patients', 'image', 'dv'));
58     
if($data['last_name']== ''){
59         echo StyleSheet() .
"\n\n<div class=\"alert alert-danger\">" . $Translation['error:'] . " 'Last name': " . $Translation['field not null'] . '<br><br>';
60         echo
'<a href="" onclick="history.go(-1); return false;">'.$Translation['< back'].'</a></div>';
61         exit;
62     }
63     
if($data['first_name']== ''){
64         echo StyleSheet() .
"\n\n<div class=\"alert alert-danger\">" . $Translation['error:'] . " 'First name': " . $Translation['field not null'] . '<br><br>';
65         echo
'<a href="" onclick="history.go(-1); return false;">'.$Translation['< back'].'</a></div>';
66         exit;
67     }
68     
if($data['gender'] == '') $data['gender'] = "Unknown";
69     
if($data['gender']== ''){
70         echo StyleSheet() .
"\n\n<div class=\"alert alert-danger\">" . $Translation['error:'] . " 'Gender': " . $Translation['field not null'] . '<br><br>';
71         echo
'<a href="" onclick="history.go(-1); return false;">'.$Translation['< back'].'</a></div>';
72         exit;
73     }
74     
if($data['sexual_orientation'] == '') $data['sexual_orientation'] = "Unknown";
75     
if($data['sexual_orientation']== ''){
76         echo StyleSheet() .
"\n\n<div class=\"alert alert-danger\">" . $Translation['error:'] . " 'Sexual orientation': " . $Translation['field not null'] . '<br><br>';
77         echo
'<a href="" onclick="history.go(-1); return false;">'.$Translation['< back'].'</a></div>';
78         exit;
79     }
80     
if($data['tobacco_usage'] == '') $data['tobacco_usage'] = "Unknown";
81     
if($data['tobacco_usage']== ''){
82         echo StyleSheet() .
"\n\n<div class=\"alert alert-danger\">" . $Translation['error:'] . " 'Tobacco usage': " . $Translation['field not null'] . '<br><br>';
83         echo
'<a href="" onclick="history.go(-1); return false;">'.$Translation['< back'].'</a></div>';
84         exit;
85     }
86     
if($data['alcohol_intake'] == '') $data['alcohol_intake'] = "Unknown";
87     
if($data['alcohol_intake']== ''){
88         echo StyleSheet() .
"\n\n<div class=\"alert alert-danger\">" . $Translation['error:'] . " 'Alcohol Intake': " . $Translation['field not null'] . '<br><br>';
89         echo
'<a href="" onclick="history.go(-1); return false;">'.$Translation['< back'].'</a></div>';
90         exit;
91     }
92     
if($data['history'] == '') $data['history'] = "Unknown";
93     
if($data['history']== ''){
94         echo StyleSheet() .
"\n\n<div class=\"alert alert-danger\">" . $Translation['error:'] . " 'History': " . $Translation['field not null'] . '<br><br>';
95         echo
'<a href="" onclick="history.go(-1); return false;">'.$Translation['< back'].'</a></div>';
96         exit;
97     }
98
99     
/* for empty upload fields, when saving a copy of an existing record, copy the original upload field */
100     
if($_REQUEST['SelectedID']){
101         $res = sql(
"select * from patients where id='" . makeSafe($_REQUEST['SelectedID']) . "'", $eo);
102         
if($row = db_fetch_assoc($res)){
103             
if(!$data['image']) $data['image'] = makeSafe($row['image']);
104         }
105     }
106
107     
// hook: patients_before_insert
108     
if(function_exists('patients_before_insert')){
109         $args=array();
110         
if(!patients_before_insert($data, getMemberInfo(), $args)){ return false; }
111     }
112
113     $o = array(
'silentErrors' => true);
114     sql(
'insert into `patients` set `last_name`=' . (($data['last_name'] !== '' && $data['last_name'] !== NULL) ? "'{$data['last_name']}'" : 'NULL') . ', `first_name`=' . (($data['first_name'] !== '' && $data['first_name'] !== NULL) ? "'{$data['first_name']}'" : 'NULL') . ', `gender`=' . (($data['gender'] !== '' && $data['gender'] !== NULL) ? "'{$data['gender']}'" : 'NULL') . ', `sexual_orientation`=' . (($data['sexual_orientation'] !== '' && $data['sexual_orientation'] !== NULL) ? "'{$data['sexual_orientation']}'" : 'NULL') . ', `birth_date`=' . (($data['birth_date'] !== '' && $data['birth_date'] !== NULL) ? "'{$data['birth_date']}'" : 'NULL') . ', ' . ($data['image'] != '' ? "`image`='{$data['image']}'" : '`image`=NULL') . ', `state`=' . (($data['state'] !== '' && $data['state'] !== NULL) ? "'{$data['state']}'" : 'NULL') . ', `mobile`=' . (($data['mobile'] !== '' && $data['mobile'] !== NULL) ? "'{$data['mobile']}'" : 'NULL') . ', `tobacco_usage`=' . (($data['tobacco_usage'] !== '' && $data['tobacco_usage'] !== NULL) ? "'{$data['tobacco_usage']}'" : 'NULL') . ', `alcohol_intake`=' . (($data['alcohol_intake'] !== '' && $data['alcohol_intake'] !== NULL) ? "'{$data['alcohol_intake']}'" : 'NULL') . ', `history`=' . (($data['history'] !== '' && $data['history'] !== NULL) ? "'{$data['history']}'" : 'NULL') . ', `surgical_history`=' . (($data['surgical_history'] !== '' && $data['surgical_history'] !== NULL) ? "'{$data['surgical_history']}'" : 'NULL') . ', `obstetric_history`=' . (($data['obstetric_history'] !== '' && $data['obstetric_history'] !== NULL) ? "'{$data['obstetric_history']}'" : 'NULL') . ', `genetic_diseases`=' . (($data['genetic_diseases'] !== '' && $data['genetic_diseases'] !== NULL) ? "'{$data['genetic_diseases']}'" : 'NULL') . ', `contact_person`=' . (($data['contact_person'] !== '' && $data['contact_person'] !== NULL) ? "'{$data['contact_person']}'" : 'NULL') . ', `other_details`=' . (($data['other_details'] !== '' && $data['other_details'] !== NULL) ? "'{$data['other_details']}'" : 'NULL') . ', `comments`=' . (($data['comments'] !== '' && $data['comments'] !== NULL) ? "'{$data['comments']}'" : 'NULL') . ', `filed`=' . "'{$data['filed']}'", $o);
115     
if($o['error']!=''){
116         echo $o[
'error'];
117         echo
"<a href=\"patients_view.php?addNew_x=1\">{$Translation['< back']}</a>";
118         exit;
119     }
120
121     $recID = db_insert_id(db_link());
122
123     
// hook: patients_after_insert
124     
if(function_exists('patients_after_insert')){
125         $res = sql(
"select * from `patients` where `id`='" . makeSafe($recID, false) . "' limit 1", $eo);
126         
if($row = db_fetch_assoc($res)){
127             $data = array_map(
'makeSafe', $row);
128         }
129         $data[
'selectedID'] = makeSafe($recID, false);
130         $args=array();
131         
if(!patients_after_insert($data, getMemberInfo(), $args)){ return $recID; }
132     }
133
134     
// mm: save ownership data
135     sql(
"insert ignore into membership_userrecords set tableName='patients', pkValue='" . makeSafe($recID, false) . "', memberID='" . makeSafe(getLoggedMemberID(), false) . "', dateAdded='" . time() . "', dateUpdated='" . time() . "', groupID='" . getLoggedGroupID() . "'", $eo);
136
137     
return $recID;
138 }
139
140 function patients_delete($selected_id, $AllowDeleteOfParents=
false, $skipChecks=false){
141     
// insure referential integrity ...
142     
global $Translation;
143     $selected_id=makeSafe($selected_id);
144
145     
// mm: can member delete record?
146     $arrPerm=getTablePermissions(
'patients');
147     $ownerGroupID=sqlValue(
"select groupID from membership_userrecords where tableName='patients' and pkValue='$selected_id'");
148     $ownerMemberID=sqlValue(
"select lcase(memberID) from membership_userrecords where tableName='patients' and pkValue='$selected_id'");
149     
if(($arrPerm[4]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[4]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[4]==3){ // allow delete?
150         
// delete allowed, so continue ...
151     }
else{
152         
return $Translation['You don\'t have enough permissions to delete this record'];
153     }
154
155     
// hook: patients_before_delete
156     
if(function_exists('patients_before_delete')){
157         $args=array();
158         
if(!patients_before_delete($selected_id, $skipChecks, getMemberInfo(), $args))
159             
return $Translation['Couldn\'t delete this record'];
160     }
161
162     
// child table: medical_records
163     $res = sql(
"select `id` from `patients` where `id`='$selected_id'", $eo);
164     $id = db_fetch_row($res);
165     $rires = sql(
"select count(1) from `medical_records` where `patient`='".addslashes($id[0])."'", $eo);
166     $rirow = db_fetch_row($rires);
167     
if($rirow[0] && !$AllowDeleteOfParents && !$skipChecks){
168         $RetMsg = $Translation[
"couldn't delete"];
169         $RetMsg = str_replace(
"<RelatedRecords>", $rirow[0], $RetMsg);
170         $RetMsg = str_replace(
"<TableName>", "medical_records", $RetMsg);
171         
return $RetMsg;
172     }elseif($rirow[
0] && $AllowDeleteOfParents && !$skipChecks){
173         $RetMsg = $Translation[
"confirm delete"];
174         $RetMsg = str_replace(
"<RelatedRecords>", $rirow[0], $RetMsg);
175         $RetMsg = str_replace(
"<TableName>", "medical_records", $RetMsg);
176         $RetMsg = str_replace(
"<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='patients_view.php?SelectedID=".urlencode($selected_id)."&delete_x=1&confirmed=1';\">", $RetMsg);
177         $RetMsg = str_replace(
"<Cancel>", "<input type=\"button\" class=\"button\" value=\"".$Translation['no']."\" onClick=\"window.location='patients_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
178         
return $RetMsg;
179     }
180
181     
// child table: events
182     $res = sql(
"select `id` from `patients` where `id`='$selected_id'", $eo);
183     $id = db_fetch_row($res);
184     $rires = sql(
"select count(1) from `events` where `name_patient`='".addslashes($id[0])."'", $eo);
185     $rirow = db_fetch_row($rires);
186     
if($rirow[0] && !$AllowDeleteOfParents && !$skipChecks){
187         $RetMsg = $Translation[
"couldn't delete"];
188         $RetMsg = str_replace(
"<RelatedRecords>", $rirow[0], $RetMsg);
189         $RetMsg = str_replace(
"<TableName>", "events", $RetMsg);
190         
return $RetMsg;
191     }elseif($rirow[
0] && $AllowDeleteOfParents && !$skipChecks){
192         $RetMsg = $Translation[
"confirm delete"];
193         $RetMsg = str_replace(
"<RelatedRecords>", $rirow[0], $RetMsg);
194         $RetMsg = str_replace(
"<TableName>", "events", $RetMsg);
195         $RetMsg = str_replace(
"<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='patients_view.php?SelectedID=".urlencode($selected_id)."&delete_x=1&confirmed=1';\">", $RetMsg);
196         $RetMsg = str_replace(
"<Cancel>", "<input type=\"button\" class=\"button\" value=\"".$Translation['no']."\" onClick=\"window.location='patients_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
197         
return $RetMsg;
198     }
199
200     sql(
"delete from `patients` where `id`='$selected_id'", $eo);
201
202     
// hook: patients_after_delete
203     
if(function_exists('patients_after_delete')){
204         $args=array();
205         patients_after_delete($selected_id, getMemberInfo(), $args);
206     }
207
208     
// mm: delete ownership data
209     sql(
"delete from membership_userrecords where tableName='patients' and pkValue='$selected_id'", $eo);
210 }
211
212 function patients_update($selected_id){
213     
global $Translation;
214
215     
// mm: can member edit record?
216     $arrPerm=getTablePermissions(
'patients');
217     $ownerGroupID=sqlValue(
"select groupID from membership_userrecords where tableName='patients' and pkValue='".makeSafe($selected_id)."'");
218     $ownerMemberID=sqlValue(
"select lcase(memberID) from membership_userrecords where tableName='patients' and pkValue='".makeSafe($selected_id)."'");
219     
if(($arrPerm[3]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[3]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[3]==3){ // allow update?
220         
// update allowed, so continue ...
221     }
else{
222         
return false;
223     }
224
225     $data[
'last_name'] = makeSafe($_REQUEST['last_name']);
226         
if($data['last_name'] == empty_lookup_value){ $data['last_name'] = ''; }
227     
if($data['last_name']==''){
228         echo StyleSheet() .
"\n\n<div class=\"alert alert-danger\">{$Translation['error:']} 'Last name': {$Translation['field not null']}<br><br>";
229         echo
'<a href="" onclick="history.go(-1); return false;">'.$Translation['< back'].'</a></div>';
230         exit;
231     }
232     $data[
'first_name'] = makeSafe($_REQUEST['first_name']);
233         
if($data['first_name'] == empty_lookup_value){ $data['first_name'] = ''; }
234     
if($data['first_name']==''){
235         echo StyleSheet() .
"\n\n<div class=\"alert alert-danger\">{$Translation['error:']} 'First name': {$Translation['field not null']}<br><br>";
236         echo
'<a href="" onclick="history.go(-1); return false;">'.$Translation['< back'].'</a></div>';
237         exit;
238     }
239     $data[
'gender'] = makeSafe($_REQUEST['gender']);
240         
if($data['gender'] == empty_lookup_value){ $data['gender'] = ''; }
241     
if($data['gender']==''){
242         echo StyleSheet() .
"\n\n<div class=\"alert alert-danger\">{$Translation['error:']} 'Gender': {$Translation['field not null']}<br><br>";
243         echo
'<a href="" onclick="history.go(-1); return false;">'.$Translation['< back'].'</a></div>';
244         exit;
245     }
246     $data[
'sexual_orientation'] = makeSafe($_REQUEST['sexual_orientation']);
247         
if($data['sexual_orientation'] == empty_lookup_value){ $data['sexual_orientation'] = ''; }
248     
if($data['sexual_orientation']==''){
249         echo StyleSheet() .
"\n\n<div class=\"alert alert-danger\">{$Translation['error:']} 'Sexual orientation': {$Translation['field not null']}<br><br>";
250         echo
'<a href="" onclick="history.go(-1); return false;">'.$Translation['< back'].'</a></div>';
251         exit;
252     }
253     $data[
'birth_date'] = intval($_REQUEST['birth_dateYear']) . '-' . intval($_REQUEST['birth_dateMonth']) . '-' . intval($_REQUEST['birth_dateDay']);
254     $data[
'birth_date'] = parseMySQLDate($data['birth_date'], '');
255     $data[
'address'] = br2nl(makeSafe($_REQUEST['address']));
256     $data[
'city'] = makeSafe($_REQUEST['city']);
257         
if($data['city'] == empty_lookup_value){ $data['city'] = ''; }
258     $data[
'state'] = makeSafe($_REQUEST['state']);
259         
if($data['state'] == empty_lookup_value){ $data['state'] = ''; }
260     $data[
'zip'] = makeSafe($_REQUEST['zip']);
261         
if($data['zip'] == empty_lookup_value){ $data['zip'] = ''; }
262     $data[
'home_phone'] = makeSafe($_REQUEST['home_phone']);
263         
if($data['home_phone'] == empty_lookup_value){ $data['home_phone'] = ''; }
264     $data[
'work_phone'] = makeSafe($_REQUEST['work_phone']);
265         
if($data['work_phone'] == empty_lookup_value){ $data['work_phone'] = ''; }
266     $data[
'mobile'] = makeSafe($_REQUEST['mobile']);
267         
if($data['mobile'] == empty_lookup_value){ $data['mobile'] = ''; }
268     $data[
'tobacco_usage'] = makeSafe($_REQUEST['tobacco_usage']);
269         
if($data['tobacco_usage'] == empty_lookup_value){ $data['tobacco_usage'] = ''; }
270     
if($data['tobacco_usage']==''){
271         echo StyleSheet() .
"\n\n<div class=\"alert alert-danger\">{$Translation['error:']} 'Tobacco usage': {$Translation['field not null']}<br><br>";
272         echo
'<a href="" onclick="history.go(-1); return false;">'.$Translation['< back'].'</a></div>';
273         exit;
274     }
275     $data[
'alcohol_intake'] = makeSafe($_REQUEST['alcohol_intake']);
276         
if($data['alcohol_intake'] == empty_lookup_value){ $data['alcohol_intake'] = ''; }
277     
if($data['alcohol_intake']==''){
278         echo StyleSheet() .
"\n\n<div class=\"alert alert-danger\">{$Translation['error:']} 'Alcohol Intake': {$Translation['field not null']}<br><br>";
279         echo
'<a href="" onclick="history.go(-1); return false;">'.$Translation['< back'].'</a></div>';
280         exit;
281     }
282     $data[
'history'] = makeSafe($_REQUEST['history']);
283         
if($data['history'] == empty_lookup_value){ $data['history'] = ''; }
284     
if($data['history']==''){
285         echo StyleSheet() .
"\n\n<div class=\"alert alert-danger\">{$Translation['error:']} 'History': {$Translation['field not null']}<br><br>";
286         echo
'<a href="" onclick="history.go(-1); return false;">'.$Translation['< back'].'</a></div>';
287         exit;
288     }
289     $data[
'surgical_history'] = br2nl(makeSafe($_REQUEST['surgical_history']));
290     $data[
'obstetric_history'] = br2nl(makeSafe($_REQUEST['obstetric_history']));
291     $data[
'genetic_diseases'] = br2nl(makeSafe($_REQUEST['genetic_diseases']));
292     $data[
'contact_person'] = makeSafe($_REQUEST['contact_person']);
293         
if($data['contact_person'] == empty_lookup_value){ $data['contact_person'] = ''; }
294     $data[
'other_details'] = br2nl(makeSafe($_REQUEST['other_details']));
295     $data[
'comments'] = makeSafe($_REQUEST['comments']);
296         
if($data['comments'] == empty_lookup_value){ $data['comments'] = ''; }
297     $data[
'last_modified'] = parseCode('<%%editingDateTime%%>', false, true);
298     $data[
'selectedID']=makeSafe($selected_id);
299     
if($_REQUEST['image_remove'] == 1){
300         $data[
'image'] = '';
301     }
else{
302         $data[
'image'] = PrepareUploadedFile('image', 1024000, 'jpg|jpeg|gif|png', false, "");
303         
if($data['image']) createThumbnail($data['image'], getThumbnailSpecs('patients', 'image', 'tv'));
304         
if($data['image']) createThumbnail($data['image'], getThumbnailSpecs('patients', 'image', 'dv'));
305     }
306
307     
// hook: patients_before_update
308     
if(function_exists('patients_before_update')){
309         $args=array();
310         
if(!patients_before_update($data, getMemberInfo(), $args)){ return false; }
311     }
312
313     $o=array(
'silentErrors' => true);
314     sql(
'update `patients` set `last_name`=' . (($data['last_name'] !== '' && $data['last_name'] !== NULL) ? "'{$data['last_name']}'" : 'NULL') . ', `first_name`=' . (($data['first_name'] !== '' && $data['first_name'] !== NULL) ? "'{$data['first_name']}'" : 'NULL') . ', `gender`=' . (($data['gender'] !== '' && $data['gender'] !== NULL) ? "'{$data['gender']}'" : 'NULL') . ', `sexual_orientation`=' . (($data['sexual_orientation'] !== '' && $data['sexual_orientation'] !== NULL) ? "'{$data['sexual_orientation']}'" : 'NULL') . ', `birth_date`=' . (($data['birth_date'] !== '' && $data['birth_date'] !== NULL) ? "'{$data['birth_date']}'" : 'NULL') . ', ' . ($data['image']!='' ? "`image`='{$data['image']}'" : ($_REQUEST['image_remove'] != 1 ? '`image`=`image`' : '`image`=NULL')) . ', `state`=' . (($data['state'] !== '' && $data['state'] !== NULL) ? "'{$data['state']}'" : 'NULL') . ', `mobile`=' . (($data['mobile'] !== '' && $data['mobile'] !== NULL) ? "'{$data['mobile']}'" : 'NULL') . ', `tobacco_usage`=' . (($data['tobacco_usage'] !== '' && $data['tobacco_usage'] !== NULL) ? "'{$data['tobacco_usage']}'" : 'NULL') . ', `alcohol_intake`=' . (($data['alcohol_intake'] !== '' && $data['alcohol_intake'] !== NULL) ? "'{$data['alcohol_intake']}'" : 'NULL') . ', `history`=' . (($data['history'] !== '' && $data['history'] !== NULL) ? "'{$data['history']}'" : 'NULL') . ', `surgical_history`=' . (($data['surgical_history'] !== '' && $data['surgical_history'] !== NULL) ? "'{$data['surgical_history']}'" : 'NULL') . ', `obstetric_history`=' . (($data['obstetric_history'] !== '' && $data['obstetric_history'] !== NULL) ? "'{$data['obstetric_history']}'" : 'NULL') . ', `genetic_diseases`=' . (($data['genetic_diseases'] !== '' && $data['genetic_diseases'] !== NULL) ? "'{$data['genetic_diseases']}'" : 'NULL') . ', `contact_person`=' . (($data['contact_person'] !== '' && $data['contact_person'] !== NULL) ? "'{$data['contact_person']}'" : 'NULL') . ', `other_details`=' . (($data['other_details'] !== '' && $data['other_details'] !== NULL) ? "'{$data['other_details']}'" : 'NULL') . ', `comments`=' . (($data['comments'] !== '' && $data['comments'] !== NULL) ? "'{$data['comments']}'" : 'NULL') . ', `filed`=`filed`' . ', `last_modified`=' . "'{$data['last_modified']}'" . " where `id`='".makeSafe($selected_id)."'", $o);
315     
if($o['error']!=''){
316         echo $o[
'error'];
317         echo
'<a href="patients_view.php?SelectedID='.urlencode($selected_id)."\">{$Translation['< back']}</a>";
318         exit;
319     }
320
321
322     
// hook: patients_after_update
323     
if(function_exists('patients_after_update')){
324         $res = sql(
"SELECT * FROM `patients` WHERE `id`='{$data['selectedID']}' LIMIT 1", $eo);
325         
if($row = db_fetch_assoc($res)){
326             $data = array_map(
'makeSafe', $row);
327         }
328         $data[
'selectedID'] = $data['id'];
329         $args = array();
330         
if(!patients_after_update($data, getMemberInfo(), $args)){ return; }
331     }
332
333     
// mm: update ownership data
334     sql(
"update membership_userrecords set dateUpdated='".time()."' where tableName='patients' and pkValue='".makeSafe($selected_id)."'", $eo);
335
336 }
337
338 function patients_form($selected_id =
'', $AllowUpdate = 1, $AllowInsert = 1, $AllowDelete = 1, $ShowCancel = 0, $TemplateDV = '', $TemplateDVP = ''){
339     
// function to return an editable form for a table records
340     
// and fill it with data of record whose ID is $selected_id. If $selected_id
341     
// is empty, an empty form is shown, with only an 'Add New'
342     
// button displayed.
343
344     
global $Translation;
345
346     
// mm: get table permissions
347     $arrPerm=getTablePermissions(
'patients');
348     
if(!$arrPerm[1] && $selected_id==''){ return ''; }
349     $AllowInsert = ($arrPerm[
1] ? true : false);
350     
// print preview?
351     $dvprint =
false;
352     
if($selected_id && $_REQUEST['dvprint_x'] != ''){
353         $dvprint =
true;
354     }
355
356
357     
// populate filterers, starting from children to grand-parents
358
359     
// unique random identifier
360     $rnd1 = ($dvprint ? rand(
1000000, 9999999) : '');
361     
// combobox: gender
362     $combo_gender =
new Combo;
363     $combo_gender->ListType =
0;
364     $combo_gender->MultipleSeparator =
', ';
365     $combo_gender->ListBoxHeight =
10;
366     $combo_gender->RadiosPerLine =
1;
367     
if(is_file(dirname(__FILE__).'/hooks/patients.gender.csv')){
368         $gender_data = addslashes(implode(
'', @file(dirname(__FILE__).'/hooks/patients.gender.csv')));
369         $combo_gender->ListItem = explode(
'||', entitiesToUTF8(convertLegacyOptions($gender_data)));
370         $combo_gender->ListData = $combo_gender->ListItem;
371     }
else{
372         $combo_gender->ListItem = explode(
'||', entitiesToUTF8(convertLegacyOptions("Unknown;;Male;;Female;;Other")));
373         $combo_gender->ListData = $combo_gender->ListItem;
374     }
375     $combo_gender->SelectName =
'gender';
376     $combo_gender->AllowNull =
false;
377     
// combobox: sexual_orientation
378     $combo_sexual_orientation =
new Combo;
379     $combo_sexual_orientation->ListType =
0;
380     $combo_sexual_orientation->MultipleSeparator =
', ';
381     $combo_sexual_orientation->ListBoxHeight =
10;
382     $combo_sexual_orientation->RadiosPerLine =
1;
383     
if(is_file(dirname(__FILE__).'/hooks/patients.sexual_orientation.csv')){
384         $sexual_orientation_data = addslashes(implode(
'', @file(dirname(__FILE__).'/hooks/patients.sexual_orientation.csv')));
385         $combo_sexual_orientation->ListItem = explode(
'||', entitiesToUTF8(convertLegacyOptions($sexual_orientation_data)));
386         $combo_sexual_orientation->ListData = $combo_sexual_orientation->ListItem;
387     }
else{
388         $combo_sexual_orientation->ListItem = explode(
'||', entitiesToUTF8(convertLegacyOptions("Unknown;;Opposite gender;;Same gender;;Asexuality;;Bisexuality")));
389         $combo_sexual_orientation->ListData = $combo_sexual_orientation->ListItem;
390     }
391     $combo_sexual_orientation->SelectName =
'sexual_orientation';
392     $combo_sexual_orientation->AllowNull =
false;
393     
// combobox: birth_date
394     $combo_birth_date =
new DateCombo;
395     $combo_birth_date->DateFormat =
"mdy";
396     $combo_birth_date->MinYear =
1900;
397     $combo_birth_date->MaxYear =
2100;
398     $combo_birth_date->DefaultDate = parseMySQLDate(
'', '');
399     $combo_birth_date->MonthNames = $Translation[
'month names'];
400     $combo_birth_date->NamePrefix =
'birth_date';
401     
// combobox: state
402     $combo_state =
new Combo;
403     $combo_state->ListType =
0;
404     $combo_state->MultipleSeparator =
', ';
405     $combo_state->ListBoxHeight =
10;
406     $combo_state->RadiosPerLine =
1;
407     
if(is_file(dirname(__FILE__).'/hooks/patients.state.csv')){
408         $state_data = addslashes(implode(
'', @file(dirname(__FILE__).'/hooks/patients.state.csv')));
409         $combo_state->ListItem = explode(
'||', entitiesToUTF8(convertLegacyOptions($state_data)));
410         $combo_state->ListData = $combo_state->ListItem;
411     }
else{
412         $combo_state->ListItem = explode(
'||', entitiesToUTF8(convertLegacyOptions("AL;;AK;;AS;;AZ;;AR;;CA;;CO;;CT;;DE;;DC;;FM;;FL;;GA;;GU;;HI;;ID;;IL;;IN;;IA;;KS;;KY;;LA;;ME;;MH;;MD;;MA;;MI;;MN;;MS;;MO;;MT;;NE;;NV;;NH;;NJ;;NM;;NY;;NC;;ND;;MP;;OH;;OK;;OR;;PW;;PA;;PR;;RI;;SC;;SD;;TN;;TX;;UT;;VT;;VI;;VA;;WA;;WV;;WI;;WY")));
413         $combo_state->ListData = $combo_state->ListItem;
414     }
415     $combo_state->SelectName =
'state';
416     
// combobox: tobacco_usage
417     $combo_tobacco_usage =
new Combo;
418     $combo_tobacco_usage->ListType =
0;
419     $combo_tobacco_usage->MultipleSeparator =
', ';
420     $combo_tobacco_usage->ListBoxHeight =
10;
421     $combo_tobacco_usage->RadiosPerLine =
1;
422     
if(is_file(dirname(__FILE__).'/hooks/patients.tobacco_usage.csv')){
423         $tobacco_usage_data = addslashes(implode(
'', @file(dirname(__FILE__).'/hooks/patients.tobacco_usage.csv')));
424         $combo_tobacco_usage->ListItem = explode(
'||', entitiesToUTF8(convertLegacyOptions($tobacco_usage_data)));
425         $combo_tobacco_usage->ListData = $combo_tobacco_usage->ListItem;
426     }
else{
427         $combo_tobacco_usage->ListItem = explode(
'||', entitiesToUTF8(convertLegacyOptions("Unknown;;Non-smoker;;Light smoker;;Average smoker;;Social smoker;;Heavy smoker;;Serial quitter;;Quitter")));
428         $combo_tobacco_usage->ListData = $combo_tobacco_usage->ListItem;
429     }
430     $combo_tobacco_usage->SelectName =
'tobacco_usage';
431     $combo_tobacco_usage->AllowNull =
false;
432     
// combobox: alcohol_intake
433     $combo_alcohol_intake =
new Combo;
434     $combo_alcohol_intake->ListType =
0;
435     $combo_alcohol_intake->MultipleSeparator =
', ';
436     $combo_alcohol_intake->ListBoxHeight =
10;
437     $combo_alcohol_intake->RadiosPerLine =
1;
438     
if(is_file(dirname(__FILE__).'/hooks/patients.alcohol_intake.csv')){
439         $alcohol_intake_data = addslashes(implode(
'', @file(dirname(__FILE__).'/hooks/patients.alcohol_intake.csv')));
440         $combo_alcohol_intake->ListItem = explode(
'||', entitiesToUTF8(convertLegacyOptions($alcohol_intake_data)));
441         $combo_alcohol_intake->ListData = $combo_alcohol_intake->ListItem;
442     }
else{
443         $combo_alcohol_intake->ListItem = explode(
'||', entitiesToUTF8(convertLegacyOptions("Unknown;;Non-drinker;;Light drinker;;Social drinker;;Pressured drinker;;Daily drinker;;Binge drinker;;Compulsive drinker;;Addicted drinker;;Serial quitter;;Quitter")));
444         $combo_alcohol_intake->ListData = $combo_alcohol_intake->ListItem;
445     }
446     $combo_alcohol_intake->SelectName =
'alcohol_intake';
447     $combo_alcohol_intake->AllowNull =
false;
448     
// combobox: history
449     $combo_history =
new Combo;
450     $combo_history->ListType =
0;
451     $combo_history->MultipleSeparator =
', ';
452     $combo_history->ListBoxHeight =
10;
453     $combo_history->RadiosPerLine =
1;
454     
if(is_file(dirname(__FILE__).'/hooks/patients.history.csv')){
455         $history_data = addslashes(implode(
'', @file(dirname(__FILE__).'/hooks/patients.history.csv')));
456         $combo_history->ListItem = explode(
'||', entitiesToUTF8(convertLegacyOptions($history_data)));
457         $combo_history->ListData = $combo_history->ListItem;
458     }
else{
459         $combo_history->ListItem = explode(
'||', entitiesToUTF8(convertLegacyOptions("Unkown;;Asthma;;Diabetes;;Blood pressure;;Medication allergies;;Food allergies;;None")));
460         $combo_history->ListData = $combo_history->ListItem;
461     }
462     $combo_history->SelectName =
'history';
463     $combo_history->AllowNull =
false;
464
465     
if($selected_id){
466         
// mm: check member permissions
467         
if(!$arrPerm[2]){
468             
return "";
469         }
470         
// mm: who is the owner?
471         $ownerGroupID=sqlValue(
"select groupID from membership_userrecords where tableName='patients' and pkValue='".makeSafe($selected_id)."'");
472         $ownerMemberID=sqlValue(
"select lcase(memberID) from membership_userrecords where tableName='patients' and pkValue='".makeSafe($selected_id)."'");
473         
if($arrPerm[2]==1 && getLoggedMemberID()!=$ownerMemberID){
474             
return "";
475         }
476         
if($arrPerm[2]==2 && getLoggedGroupID()!=$ownerGroupID){
477             
return "";
478         }
479
480         
// can edit?
481         
if(($arrPerm[3]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[3]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[3]==3){
482             $AllowUpdate=
1;
483         }
else{
484             $AllowUpdate=
0;
485         }
486
487         $res = sql(
"select * from `patients` where `id`='".makeSafe($selected_id)."'", $eo);
488         
if(!($row = db_fetch_array($res))){
489             
return error_message($Translation['No records found'], 'patients_view.php', false);
490         }
491         $urow = $row;
/* unsanitized data */
492         $hc =
new CI_Input();
493         $row = $hc->xss_clean($row);
/* sanitize data */
494         $combo_gender->SelectedData = $row[
'gender'];
495         $combo_sexual_orientation->SelectedData = $row[
'sexual_orientation'];
496         $combo_birth_date->DefaultDate = $row[
'birth_date'];
497         $combo_state->SelectedData = $row[
'state'];
498         $combo_tobacco_usage->SelectedData = $row[
'tobacco_usage'];
499         $combo_alcohol_intake->SelectedData = $row[
'alcohol_intake'];
500         $combo_history->SelectedData = $row[
'history'];
501         $row[
'filed'] = sqlValue("select DATE_FORMAT(`filed`, '%c/%e/%Y %l:%i%p') from `patients` where `id`='".makeSafe($selected_id)."'");
502         $row[
'last_modified'] = sqlValue("select DATE_FORMAT(`last_modified`, '%c/%e/%Y %l:%i%p') from `patients` where `id`='".makeSafe($selected_id)."'");
503     }
else{
504         $combo_gender->SelectedText = ( $_REQUEST[
'FilterField'][1]=='4' && $_REQUEST['FilterOperator'][1]=='<=>' ? (get_magic_quotes_gpc() ? stripslashes($_REQUEST['FilterValue'][1]) : $_REQUEST['FilterValue'][1]) : "Unknown");
505         $combo_sexual_orientation->SelectedText = ( $_REQUEST[
'FilterField'][1]=='5' && $_REQUEST['FilterOperator'][1]=='<=>' ? (get_magic_quotes_gpc() ? stripslashes($_REQUEST['FilterValue'][1]) : $_REQUEST['FilterValue'][1]) : "Unknown");
506         $combo_state->SelectedText = ( $_REQUEST[
'FilterField'][1]=='11' && $_REQUEST['FilterOperator'][1]=='<=>' ? (get_magic_quotes_gpc() ? stripslashes($_REQUEST['FilterValue'][1]) : $_REQUEST['FilterValue'][1]) : "");
507         $combo_tobacco_usage->SelectedText = ( $_REQUEST[
'FilterField'][1]=='16' && $_REQUEST['FilterOperator'][1]=='<=>' ? (get_magic_quotes_gpc() ? stripslashes($_REQUEST['FilterValue'][1]) : $_REQUEST['FilterValue'][1]) : "Unknown");
508         $combo_alcohol_intake->SelectedText = ( $_REQUEST[
'FilterField'][1]=='17' && $_REQUEST['FilterOperator'][1]=='<=>' ? (get_magic_quotes_gpc() ? stripslashes($_REQUEST['FilterValue'][1]) : $_REQUEST['FilterValue'][1]) : "Unknown");
509         $combo_history->SelectedText = ( $_REQUEST[
'FilterField'][1]=='18' && $_REQUEST['FilterOperator'][1]=='<=>' ? (get_magic_quotes_gpc() ? stripslashes($_REQUEST['FilterValue'][1]) : $_REQUEST['FilterValue'][1]) : "Unknown");
510     }
511     $combo_gender->Render();
512     $combo_sexual_orientation->Render();
513     $combo_state->Render();
514     $combo_tobacco_usage->Render();
515     $combo_alcohol_intake->Render();
516     $combo_history->Render();
517
518     
// code for template based detail view forms
519
520     
// open the detail view template
521     
if($dvprint){
522         $template_file = is_file(
"./{$TemplateDVP}") ? "./{$TemplateDVP}" : './templates/patients_templateDVP.html';
523         $templateCode = @file_get_contents($template_file);
524     }
else{
525         $template_file = is_file(
"./{$TemplateDV}") ? "./{$TemplateDV}" : './templates/patients_templateDV.html';
526         $templateCode = @file_get_contents($template_file);
527     }
528
529     
// process form title
530     $templateCode = str_replace(
'<%%DETAIL_VIEW_TITLE%%>', 'Patient details', $templateCode);
531     $templateCode = str_replace(
'<%%RND1%%>', $rnd1, $templateCode);
532     $templateCode = str_replace(
'<%%EMBEDDED%%>', ($_REQUEST['Embedded'] ? 'Embedded=1' : ''), $templateCode);
533     
// process buttons
534     
if($arrPerm[1] && !$selected_id){ // allow insert and no record selected?
535         
if(!$selected_id) $templateCode=str_replace('<%%INSERT_BUTTON%%>', '<button type="submit" class="btn btn-success" id="insert" name="insert_x" value="1" onclick="return patients_validateData();"><i class="glyphicon glyphicon-plus-sign"></i> ' . $Translation['Save New'] . '</button>', $templateCode);
536         $templateCode=str_replace(
'<%%INSERT_BUTTON%%>', '<button type="submit" class="btn btn-default" id="insert" name="insert_x" value="1" onclick="return patients_validateData();"><i class="glyphicon glyphicon-plus-sign"></i> ' . $Translation['Save As Copy'] . '</button>', $templateCode);
537     }
else{
538         $templateCode=str_replace(
'<%%INSERT_BUTTON%%>', '', $templateCode);
539     }
540
541     
// 'Back' button action
542     
if($_REQUEST['Embedded']){
543         $backAction =
'window.parent.jQuery(\'.modal\').modal(\'hide\'); return false;';
544     }
else{
545         $backAction =
'$$(\'form\')[0].writeAttribute(\'novalidate\', \'novalidate\'); document.myform.reset(); return true;';
546     }
547
548     
if($selected_id){
549         
if(!$_REQUEST['Embedded']) $templateCode=str_replace('<%%DVPRINT_BUTTON%%>', '<button type="submit" class="btn btn-default" id="dvprint" name="dvprint_x" value="1" onclick="$$(\'form\')[0].writeAttribute(\'novalidate\', \'novalidate\'); document.myform.reset(); return true;" title="' . html_attr($Translation['Print Preview']) . '"><i class="glyphicon glyphicon-print"></i> ' . $Translation['Print Preview'] . '</button>', $templateCode);
550         
if($AllowUpdate){
551             $templateCode=str_replace(
'<%%UPDATE_BUTTON%%>', '<button type="submit" class="btn btn-success btn-lg" id="update" name="update_x" value="1" onclick="return patients_validateData();" title="' . html_attr($Translation['Save Changes']) . '"><i class="glyphicon glyphicon-ok"></i> ' . $Translation['Save Changes'] . '</button>', $templateCode);
552         }
else{
553             $templateCode=str_replace(
'<%%UPDATE_BUTTON%%>', '', $templateCode);
554         }
555         
if(($arrPerm[4]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[4]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[4]==3){ // allow delete?
556             $templateCode=str_replace(
'<%%DELETE_BUTTON%%>', '<button type="submit" class="btn btn-danger" id="delete" name="delete_x" value="1" onclick="return confirm(\'' . $Translation['are you sure?'] . '\');" title="' . html_attr($Translation['Delete']) . '"><i class="glyphicon glyphicon-trash"></i> ' . $Translation['Delete'] . '</button>', $templateCode);
557         }
else{
558             $templateCode=str_replace(
'<%%DELETE_BUTTON%%>', '', $templateCode);
559         }
560         $templateCode=str_replace(
'<%%DESELECT_BUTTON%%>', '<button type="submit" class="btn btn-default" id="deselect" name="deselect_x" value="1" onclick="' . $backAction . '" title="' . html_attr($Translation['Back']) . '"><i class="glyphicon glyphicon-chevron-left"></i> ' . $Translation['Back'] . '</button>', $templateCode);
561     }
else{
562         $templateCode=str_replace(
'<%%UPDATE_BUTTON%%>', '', $templateCode);
563         $templateCode=str_replace(
'<%%DELETE_BUTTON%%>', '', $templateCode);
564         $templateCode=str_replace(
'<%%DESELECT_BUTTON%%>', ($ShowCancel ? '<button type="submit" class="btn btn-default" id="deselect" name="deselect_x" value="1" onclick="' . $backAction . '" title="' . html_attr($Translation['Back']) . '"><i class="glyphicon glyphicon-chevron-left"></i> ' . $Translation['Back'] . '</button>' : ''), $templateCode);
565     }
566
567     
// set records to read only if user can't insert new records and can't edit current record
568     
if(($selected_id && !$AllowUpdate) || (!$selected_id && !$AllowInsert)){
569         $jsReadOnly .=
"\tjQuery('#last_name').replaceWith('<div class=\"form-control-static\" id=\"last_name\">' + (jQuery('#last_name').val() || '') + '</div>');\n";
570         $jsReadOnly .=
"\tjQuery('#first_name').replaceWith('<div class=\"form-control-static\" id=\"first_name\">' + (jQuery('#first_name').val() || '') + '</div>');\n";
571         $jsReadOnly .=
"\tjQuery('#gender').replaceWith('<div class=\"form-control-static\" id=\"gender\">' + (jQuery('#gender').val() || '') + '</div>'); jQuery('#gender-multi-selection-help').hide();\n";
572         $jsReadOnly .=
"\tjQuery('#sexual_orientation').replaceWith('<div class=\"form-control-static\" id=\"sexual_orientation\">' + (jQuery('#sexual_orientation').val() || '') + '</div>'); jQuery('#sexual_orientation-multi-selection-help').hide();\n";
573         $jsReadOnly .=
"\tjQuery('#birth_date').prop('readonly', true);\n";
574         $jsReadOnly .=
"\tjQuery('#birth_dateDay, #birth_dateMonth, #birth_dateYear').prop('disabled', true).css({ color: '#555', backgroundColor: '#fff' });\n";
575         $jsReadOnly .=
"\tjQuery('#image').replaceWith('<div class=\"form-control-static\" id=\"image\">' + (jQuery('#image').val() || '') + '</div>');\n";
576         $jsReadOnly .=
"\tjQuery('#state').replaceWith('<div class=\"form-control-static\" id=\"state\">' + (jQuery('#state').val() || '') + '</div>'); jQuery('#state-multi-selection-help').hide();\n";
577         $jsReadOnly .=
"\tjQuery('#mobile').replaceWith('<div class=\"form-control-static\" id=\"mobile\">' + (jQuery('#mobile').val() || '') + '</div>');\n";
578         $jsReadOnly .=
"\tjQuery('#tobacco_usage').replaceWith('<div class=\"form-control-static\" id=\"tobacco_usage\">' + (jQuery('#tobacco_usage').val() || '') + '</div>'); jQuery('#tobacco_usage-multi-selection-help').hide();\n";
579         $jsReadOnly .=
"\tjQuery('#alcohol_intake').replaceWith('<div class=\"form-control-static\" id=\"alcohol_intake\">' + (jQuery('#alcohol_intake').val() || '') + '</div>'); jQuery('#alcohol_intake-multi-selection-help').hide();\n";
580         $jsReadOnly .=
"\tjQuery('#history').replaceWith('<div class=\"form-control-static\" id=\"history\">' + (jQuery('#history').val() || '') + '</div>'); jQuery('#history-multi-selection-help').hide();\n";
581         $jsReadOnly .=
"\tjQuery('#surgical_history').replaceWith('<div class=\"form-control-static\" id=\"surgical_history\">' + (jQuery('#surgical_history').val() || '') + '</div>');\n";
582         $jsReadOnly .=
"\tjQuery('#obstetric_history').replaceWith('<div class=\"form-control-static\" id=\"obstetric_history\">' + (jQuery('#obstetric_history').val() || '') + '</div>');\n";
583         $jsReadOnly .=
"\tjQuery('#genetic_diseases').replaceWith('<div class=\"form-control-static\" id=\"genetic_diseases\">' + (jQuery('#genetic_diseases').val() || '') + '</div>');\n";
584         $jsReadOnly .=
"\tjQuery('#contact_person').replaceWith('<div class=\"form-control-static\" id=\"contact_person\">' + (jQuery('#contact_person').val() || '') + '</div>');\n";
585         $jsReadOnly .=
"\tjQuery('#other_details').replaceWith('<div class=\"form-control-static\" id=\"other_details\">' + (jQuery('#other_details').val() || '') + '</div>');\n";
586         $jsReadOnly .=
"\tjQuery('.select2-container').hide();\n";
587
588         $noUploads =
true;
589     }elseif(($AllowInsert && !$selected_id) || ($AllowUpdate && $selected_id)){
590         $jsEditable .=
"\tjQuery('form').eq(0).data('already_changed', true);"; // temporarily disable form change handler
591             $jsEditable .=
"\tjQuery('form').eq(0).data('already_changed', false);"; // re-enable form change handler
592     }
593
594     
// process combos
595     $templateCode=str_replace(
'<%%COMBO(gender)%%>', $combo_gender->HTML, $templateCode);
596     $templateCode=str_replace(
'<%%COMBOTEXT(gender)%%>', $combo_gender->SelectedData, $templateCode);
597     $templateCode=str_replace(
'<%%COMBO(sexual_orientation)%%>', $combo_sexual_orientation->HTML, $templateCode);
598     $templateCode=str_replace(
'<%%COMBOTEXT(sexual_orientation)%%>', $combo_sexual_orientation->SelectedData, $templateCode);
599     $templateCode=str_replace(
'<%%COMBO(birth_date)%%>', ($selected_id && !$arrPerm[3] ? '<div class="form-control-static">' . $combo_birth_date->GetHTML(true) . '</div>' : $combo_birth_date->GetHTML()), $templateCode);
600     $templateCode=str_replace(
'<%%COMBOTEXT(birth_date)%%>', $combo_birth_date->GetHTML(true), $templateCode);
601     $templateCode=str_replace(
'<%%COMBO(state)%%>', $combo_state->HTML, $templateCode);
602     $templateCode=str_replace(
'<%%COMBOTEXT(state)%%>', $combo_state->SelectedData, $templateCode);
603     $templateCode=str_replace(
'<%%COMBO(tobacco_usage)%%>', $combo_tobacco_usage->HTML, $templateCode);
604     $templateCode=str_replace(
'<%%COMBOTEXT(tobacco_usage)%%>', $combo_tobacco_usage->SelectedData, $templateCode);
605     $templateCode=str_replace(
'<%%COMBO(alcohol_intake)%%>', $combo_alcohol_intake->HTML, $templateCode);
606     $templateCode=str_replace(
'<%%COMBOTEXT(alcohol_intake)%%>', $combo_alcohol_intake->SelectedData, $templateCode);
607     $templateCode=str_replace(
'<%%COMBO(history)%%>', $combo_history->HTML, $templateCode);
608     $templateCode=str_replace(
'<%%COMBOTEXT(history)%%>', $combo_history->SelectedData, $templateCode);
609
610     
/* lookup fields array: 'lookup field name' => array('parent table name', 'lookup field caption') */
611     $lookup_fields = array();
612     
foreach($lookup_fields as $luf => $ptfc){
613         $pt_perm = getTablePermissions($ptfc[
0]);
614
615         
// process foreign key links
616         
if($pt_perm['view'] || $pt_perm['edit']){
617             $templateCode = str_replace(
"<%%PLINK({$luf})%%>", '<button type="button" class="btn btn-default view_parent hspacer-md" id="' . $ptfc[0] . '_view_parent" title="' . html_attr($Translation['View'] . ' ' . $ptfc[1]) . '"><i class="glyphicon glyphicon-eye-open"></i></button>', $templateCode);
618         }
619
620         
// if user has insert permission to parent table of a lookup field, put an add new button
621         
if($pt_perm['insert'] && !$_REQUEST['Embedded']){
622             $templateCode = str_replace(
"<%%ADDNEW({$ptfc[0]})%%>", '<button type="button" class="btn btn-success add_new_parent hspacer-md" id="' . $ptfc[0] . '_add_new" title="' . html_attr($Translation['Add New'] . ' ' . $ptfc[1]) . '"><i class="glyphicon glyphicon-plus-sign"></i></button>', $templateCode);
623         }
624     }
625
626     
// process images
627     $templateCode=str_replace(
'<%%UPLOADFILE(id)%%>', '', $templateCode);
628     $templateCode=str_replace(
'<%%UPLOADFILE(last_name)%%>', '', $templateCode);
629     $templateCode=str_replace(
'<%%UPLOADFILE(first_name)%%>', '', $templateCode);
630     $templateCode=str_replace(
'<%%UPLOADFILE(gender)%%>', '', $templateCode);
631     $templateCode=str_replace(
'<%%UPLOADFILE(sexual_orientation)%%>', '', $templateCode);
632     $templateCode=str_replace(
'<%%UPLOADFILE(birth_date)%%>', '', $templateCode);
633     $templateCode=str_replace(
'<%%UPLOADFILE(age)%%>', '', $templateCode);
634     $templateCode=str_replace(
'<%%UPLOADFILE(image)%%>', ($noUploads ? '' : '<input type=hidden name=MAX_FILE_SIZE value=1024000>'.$Translation['upload image'].' <input type="file" name="image" id="image">'), $templateCode);
635     
if($AllowUpdate && $row['image']!=''){
636         $templateCode=str_replace(
'<%%REMOVEFILE(image)%%>', '<br><input type="checkbox" name="image_remove" id="image_remove" value="1"> <label for="image_remove" style="color: red; font-weight: bold;">'.$Translation['remove image'].'</label>', $templateCode);
637     }
else{
638         $templateCode=str_replace(
'<%%REMOVEFILE(image)%%>', '', $templateCode);
639     }
640     $templateCode=str_replace(
'<%%UPLOADFILE(address)%%>', '', $templateCode);
641     $templateCode=str_replace(
'<%%UPLOADFILE(city)%%>', '', $templateCode);
642     $templateCode=str_replace(
'<%%UPLOADFILE(state)%%>', '', $templateCode);
643     $templateCode=str_replace(
'<%%UPLOADFILE(zip)%%>', '', $templateCode);
644     $templateCode=str_replace(
'<%%UPLOADFILE(home_phone)%%>', '', $templateCode);
645     $templateCode=str_replace(
'<%%UPLOADFILE(work_phone)%%>', '', $templateCode);
646     $templateCode=str_replace(
'<%%UPLOADFILE(mobile)%%>', '', $templateCode);
647     $templateCode=str_replace(
'<%%UPLOADFILE(tobacco_usage)%%>', '', $templateCode);
648     $templateCode=str_replace(
'<%%UPLOADFILE(alcohol_intake)%%>', '', $templateCode);
649     $templateCode=str_replace(
'<%%UPLOADFILE(history)%%>', '', $templateCode);
650     $templateCode=str_replace(
'<%%UPLOADFILE(surgical_history)%%>', '', $templateCode);
651     $templateCode=str_replace(
'<%%UPLOADFILE(obstetric_history)%%>', '', $templateCode);
652     $templateCode=str_replace(
'<%%UPLOADFILE(genetic_diseases)%%>', '', $templateCode);
653     $templateCode=str_replace(
'<%%UPLOADFILE(contact_person)%%>', '', $templateCode);
654     $templateCode=str_replace(
'<%%UPLOADFILE(other_details)%%>', '', $templateCode);
655     $templateCode=str_replace(
'<%%UPLOADFILE(comments)%%>', '', $templateCode);
656     $templateCode=str_replace(
'<%%UPLOADFILE(filed)%%>', '', $templateCode);
657     $templateCode=str_replace(
'<%%UPLOADFILE(last_modified)%%>', '', $templateCode);
658
659     
// process values
660     
if($selected_id){
661         $templateCode=str_replace(
'<%%VALUE(id)%%>', html_attr($row['id']), $templateCode);
662         $templateCode=str_replace(
'<%%URLVALUE(id)%%>', urlencode($urow['id']), $templateCode);
663         $templateCode=str_replace(
'<%%VALUE(last_name)%%>', html_attr($row['last_name']), $templateCode);
664         $templateCode=str_replace(
'<%%URLVALUE(last_name)%%>', urlencode($urow['last_name']), $templateCode);
665         $templateCode=str_replace(
'<%%VALUE(first_name)%%>', html_attr($row['first_name']), $templateCode);
666         $templateCode=str_replace(
'<%%URLVALUE(first_name)%%>', urlencode($urow['first_name']), $templateCode);
667         $templateCode=str_replace(
'<%%VALUE(gender)%%>', html_attr($row['gender']), $templateCode);
668         $templateCode=str_replace(
'<%%URLVALUE(gender)%%>', urlencode($urow['gender']), $templateCode);
669         $templateCode=str_replace(
'<%%VALUE(sexual_orientation)%%>', html_attr($row['sexual_orientation']), $templateCode);
670         $templateCode=str_replace(
'<%%URLVALUE(sexual_orientation)%%>', urlencode($urow['sexual_orientation']), $templateCode);
671         $templateCode=str_replace(
'<%%VALUE(birth_date)%%>', @date('m/d/Y', @strtotime(html_attr($row['birth_date']))), $templateCode);
672         $templateCode=str_replace(
'<%%URLVALUE(birth_date)%%>', urlencode(@date('m/d/Y', @strtotime(html_attr($urow['birth_date'])))), $templateCode);
673         $templateCode=str_replace(
'<%%VALUE(age)%%>', html_attr($row['age']), $templateCode);
674         $templateCode=str_replace(
'<%%URLVALUE(age)%%>', urlencode($urow['age']), $templateCode);
675         $row[
'image']=($row['image']!=''?$row['image']:'blank.gif');
676         $templateCode=str_replace(
'<%%VALUE(image)%%>', html_attr($row['image']), $templateCode);
677         $templateCode=str_replace(
'<%%URLVALUE(image)%%>', urlencode($urow['image']), $templateCode);
678         
if($dvprint){
679             $templateCode = str_replace(
'<%%VALUE(address)%%>', nl2br(html_attr($row['address'])), $templateCode);
680         }
else{
681             $templateCode = str_replace(
'<%%VALUE(address)%%>', html_attr($row['address']), $templateCode);
682         }
683         $templateCode=str_replace(
'<%%URLVALUE(address)%%>', urlencode($urow['address']), $templateCode);
684         $templateCode=str_replace(
'<%%VALUE(city)%%>', html_attr($row['city']), $templateCode);
685         $templateCode=str_replace(
'<%%URLVALUE(city)%%>', urlencode($urow['city']), $templateCode);
686         $templateCode=str_replace(
'<%%VALUE(state)%%>', html_attr($row['state']), $templateCode);
687         $templateCode=str_replace(
'<%%URLVALUE(state)%%>', urlencode($urow['state']), $templateCode);
688         $templateCode=str_replace(
'<%%VALUE(zip)%%>', html_attr($row['zip']), $templateCode);
689         $templateCode=str_replace(
'<%%URLVALUE(zip)%%>', urlencode($urow['zip']), $templateCode);
690         $templateCode=str_replace(
'<%%VALUE(home_phone)%%>', html_attr($row['home_phone']), $templateCode);
691         $templateCode=str_replace(
'<%%URLVALUE(home_phone)%%>', urlencode($urow['home_phone']), $templateCode);
692         $templateCode=str_replace(
'<%%VALUE(work_phone)%%>', html_attr($row['work_phone']), $templateCode);
693         $templateCode=str_replace(
'<%%URLVALUE(work_phone)%%>', urlencode($urow['work_phone']), $templateCode);
694         $templateCode=str_replace(
'<%%VALUE(mobile)%%>', html_attr($row['mobile']), $templateCode);
695         $templateCode=str_replace(
'<%%URLVALUE(mobile)%%>', urlencode($urow['mobile']), $templateCode);
696         $templateCode=str_replace(
'<%%VALUE(tobacco_usage)%%>', html_attr($row['tobacco_usage']), $templateCode);
697         $templateCode=str_replace(
'<%%URLVALUE(tobacco_usage)%%>', urlencode($urow['tobacco_usage']), $templateCode);
698         $templateCode=str_replace(
'<%%VALUE(alcohol_intake)%%>', html_attr($row['alcohol_intake']), $templateCode);
699         $templateCode=str_replace(
'<%%URLVALUE(alcohol_intake)%%>', urlencode($urow['alcohol_intake']), $templateCode);
700         $templateCode=str_replace(
'<%%VALUE(history)%%>', html_attr($row['history']), $templateCode);
701         $templateCode=str_replace(
'<%%URLVALUE(history)%%>', urlencode($urow['history']), $templateCode);
702         
if($dvprint){
703             $templateCode = str_replace(
'<%%VALUE(surgical_history)%%>', nl2br(html_attr($row['surgical_history'])), $templateCode);
704         }
else{
705             $templateCode = str_replace(
'<%%VALUE(surgical_history)%%>', html_attr($row['surgical_history']), $templateCode);
706         }
707         $templateCode=str_replace(
'<%%URLVALUE(surgical_history)%%>', urlencode($urow['surgical_history']), $templateCode);
708         
if($dvprint){
709             $templateCode = str_replace(
'<%%VALUE(obstetric_history)%%>', nl2br(html_attr($row['obstetric_history'])), $templateCode);
710         }
else{
711             $templateCode = str_replace(
'<%%VALUE(obstetric_history)%%>', html_attr($row['obstetric_history']), $templateCode);
712         }
713         $templateCode=str_replace(
'<%%URLVALUE(obstetric_history)%%>', urlencode($urow['obstetric_history']), $templateCode);
714         
if($dvprint){
715             $templateCode = str_replace(
'<%%VALUE(genetic_diseases)%%>', nl2br(html_attr($row['genetic_diseases'])), $templateCode);
716         }
else{
717             $templateCode = str_replace(
'<%%VALUE(genetic_diseases)%%>', html_attr($row['genetic_diseases']), $templateCode);
718         }
719         $templateCode=str_replace(
'<%%URLVALUE(genetic_diseases)%%>', urlencode($urow['genetic_diseases']), $templateCode);
720         $templateCode=str_replace(
'<%%VALUE(contact_person)%%>', html_attr($row['contact_person']), $templateCode);
721         $templateCode=str_replace(
'<%%URLVALUE(contact_person)%%>', urlencode($urow['contact_person']), $templateCode);
722         
if($dvprint){
723             $templateCode = str_replace(
'<%%VALUE(other_details)%%>', nl2br(html_attr($row['other_details'])), $templateCode);
724         }
else{
725             $templateCode = str_replace(
'<%%VALUE(other_details)%%>', html_attr($row['other_details']), $templateCode);
726         }
727         $templateCode=str_replace(
'<%%URLVALUE(other_details)%%>', urlencode($urow['other_details']), $templateCode);
728         
if($AllowUpdate || $AllowInsert){
729             $templateCode = str_replace(
'<%%HTMLAREA(comments)%%>', '<textarea name="comments" id="comments" rows="5">' . html_attr($row['comments']) . '</textarea>', $templateCode);
730         }
else{
731             $templateCode = str_replace(
'<%%HTMLAREA(comments)%%>', '<div id="comments" class="form-control-static">' . $row['comments'] . '</div>', $templateCode);
732         }
733         $templateCode=str_replace(
'<%%VALUE(comments)%%>', nl2br($row['comments']), $templateCode);
734         $templateCode=str_replace(
'<%%URLVALUE(comments)%%>', urlencode($urow['comments']), $templateCode);
735         $templateCode=str_replace(
'<%%VALUE(filed)%%>', html_attr($row['filed']), $templateCode);
736         $templateCode=str_replace(
'<%%URLVALUE(filed)%%>', urlencode($urow['filed']), $templateCode);
737         $templateCode=str_replace(
'<%%VALUE(last_modified)%%>', html_attr($row['last_modified']), $templateCode);
738         $templateCode=str_replace(
'<%%URLVALUE(last_modified)%%>', urlencode($urow['last_modified']), $templateCode);
739     }
else{
740         $templateCode=str_replace(
'<%%VALUE(id)%%>', '', $templateCode);
741         $templateCode=str_replace(
'<%%URLVALUE(id)%%>', urlencode(''), $templateCode);
742         $templateCode=str_replace(
'<%%VALUE(last_name)%%>', '', $templateCode);
743         $templateCode=str_replace(
'<%%URLVALUE(last_name)%%>', urlencode(''), $templateCode);
744         $templateCode=str_replace(
'<%%VALUE(first_name)%%>', '', $templateCode);
745         $templateCode=str_replace(
'<%%URLVALUE(first_name)%%>', urlencode(''), $templateCode);
746         $templateCode=str_replace(
'<%%VALUE(gender)%%>', 'Unknown', $templateCode);
747         $templateCode=str_replace(
'<%%URLVALUE(gender)%%>', urlencode('Unknown'), $templateCode);
748         $templateCode=str_replace(
'<%%VALUE(sexual_orientation)%%>', 'Unknown', $templateCode);
749         $templateCode=str_replace(
'<%%URLVALUE(sexual_orientation)%%>', urlencode('Unknown'), $templateCode);
750         $templateCode=str_replace(
'<%%VALUE(birth_date)%%>', '', $templateCode);
751         $templateCode=str_replace(
'<%%URLVALUE(birth_date)%%>', urlencode(''), $templateCode);
752         $templateCode=str_replace(
'<%%VALUE(age)%%>', '', $templateCode);
753         $templateCode=str_replace(
'<%%URLVALUE(age)%%>', urlencode(''), $templateCode);
754         $templateCode=str_replace(
'<%%VALUE(image)%%>', 'blank.gif', $templateCode);
755         $templateCode=str_replace(
'<%%VALUE(address)%%>', '', $templateCode);
756         $templateCode=str_replace(
'<%%URLVALUE(address)%%>', urlencode(''), $templateCode);
757         $templateCode=str_replace(
'<%%VALUE(city)%%>', '', $templateCode);
758         $templateCode=str_replace(
'<%%URLVALUE(city)%%>', urlencode(''), $templateCode);
759         $templateCode=str_replace(
'<%%VALUE(state)%%>', '', $templateCode);
760         $templateCode=str_replace(
'<%%URLVALUE(state)%%>', urlencode(''), $templateCode);
761         $templateCode=str_replace(
'<%%VALUE(zip)%%>', '', $templateCode);
762         $templateCode=str_replace(
'<%%URLVALUE(zip)%%>', urlencode(''), $templateCode);
763         $templateCode=str_replace(
'<%%VALUE(home_phone)%%>', '', $templateCode);
764         $templateCode=str_replace(
'<%%URLVALUE(home_phone)%%>', urlencode(''), $templateCode);
765         $templateCode=str_replace(
'<%%VALUE(work_phone)%%>', '', $templateCode);
766         $templateCode=str_replace(
'<%%URLVALUE(work_phone)%%>', urlencode(''), $templateCode);
767         $templateCode=str_replace(
'<%%VALUE(mobile)%%>', '', $templateCode);
768         $templateCode=str_replace(
'<%%URLVALUE(mobile)%%>', urlencode(''), $templateCode);
769         $templateCode=str_replace(
'<%%VALUE(tobacco_usage)%%>', 'Unknown', $templateCode);
770         $templateCode=str_replace(
'<%%URLVALUE(tobacco_usage)%%>', urlencode('Unknown'), $templateCode);
771         $templateCode=str_replace(
'<%%VALUE(alcohol_intake)%%>', 'Unknown', $templateCode);
772         $templateCode=str_replace(
'<%%URLVALUE(alcohol_intake)%%>', urlencode('Unknown'), $templateCode);
773         $templateCode=str_replace(
'<%%VALUE(history)%%>', 'Unknown', $templateCode);
774         $templateCode=str_replace(
'<%%URLVALUE(history)%%>', urlencode('Unknown'), $templateCode);
775         $templateCode=str_replace(
'<%%VALUE(surgical_history)%%>', '', $templateCode);
776         $templateCode=str_replace(
'<%%URLVALUE(surgical_history)%%>', urlencode(''), $templateCode);
777         $templateCode=str_replace(
'<%%VALUE(obstetric_history)%%>', '', $templateCode);
778         $templateCode=str_replace(
'<%%URLVALUE(obstetric_history)%%>', urlencode(''), $templateCode);
779         $templateCode=str_replace(
'<%%VALUE(genetic_diseases)%%>', '', $templateCode);
780         $templateCode=str_replace(
'<%%URLVALUE(genetic_diseases)%%>', urlencode(''), $templateCode);
781         $templateCode=str_replace(
'<%%VALUE(contact_person)%%>', '', $templateCode);
782         $templateCode=str_replace(
'<%%URLVALUE(contact_person)%%>', urlencode(''), $templateCode);
783         $templateCode=str_replace(
'<%%VALUE(other_details)%%>', '', $templateCode);
784         $templateCode=str_replace(
'<%%URLVALUE(other_details)%%>', urlencode(''), $templateCode);
785         $templateCode=str_replace(
'<%%HTMLAREA(comments)%%>', '<textarea name="comments" id="comments" rows="5"></textarea>', $templateCode);
786         $templateCode=str_replace(
'<%%VALUE(filed)%%>', '<%%creationDateTime%%>', $templateCode);
787         $templateCode=str_replace(
'<%%URLVALUE(filed)%%>', urlencode('<%%creationDateTime%%>'), $templateCode);
788         $templateCode=str_replace(
'<%%VALUE(last_modified)%%>', '<%%editingDateTime%%>', $templateCode);
789         $templateCode=str_replace(
'<%%URLVALUE(last_modified)%%>', urlencode('<%%editingDateTime%%>'), $templateCode);
790     }
791
792     
// process translations
793     
foreach($Translation as $symbol=>$trans){
794         $templateCode=str_replace(
"<%%TRANSLATION($symbol)%%>", $trans, $templateCode);
795     }
796
797     
// clear scrap
798     $templateCode=str_replace(
'<%%', '<!-- ', $templateCode);
799     $templateCode=str_replace(
'%%>', ' -->', $templateCode);
800
801     
// hide links to inaccessible tables
802     
if($_REQUEST['dvprint_x'] == ''){
803         $templateCode .=
"\n\n<script>\$j(function(){\n";
804         $arrTables = getTableList();
805         
foreach($arrTables as $name => $caption){
806             $templateCode .=
"\t\$j('#{$name}_link').removeClass('hidden');\n";
807             $templateCode .=
"\t\$j('#xs_{$name}_link').removeClass('hidden');\n";
808         }
809
810         $templateCode .= $jsReadOnly;
811         $templateCode .= $jsEditable;
812
813         
if(!$selected_id){
814         }
815
816         $templateCode.=
"\n});</script>\n";
817     }
818
819     
// ajaxed auto-fill fields
820     $templateCode .=
'<script>';
821     $templateCode .=
'$j(function() {';
822
823
824     $templateCode.=
"});";
825     $templateCode.=
"</script>";
826     $templateCode .= $lookups;
827
828     
// handle enforced parent values for read-only lookup fields
829
830     
// don't include blank images in lightbox gallery
831     $templateCode = preg_replace(
'/blank.gif" data-lightbox=".*?"/', 'blank.gif"', $templateCode);
832
833     
// don't display empty email links
834     $templateCode=preg_replace(
'/<a .*?href="mailto:".*?<\/a>/', '', $templateCode);
835
836     
/* default field values */
837     $rdata = $jdata = get_defaults(
'patients');
838     
if($selected_id){
839         $jdata = get_joined_record(
'patients', $selected_id);
840         $rdata = $row;
841     }
842     $cache_data = array(
843         
'rdata' => array_map('nl2br', array_map('addslashes', $rdata)),
844         
'jdata' => array_map('nl2br', array_map('addslashes', $jdata)),
845     );
846     $templateCode .= loadView(
'patients-ajax-cache', $cache_data);
847
848     
// hook: patients_dv
849     
if(function_exists('patients_dv')){
850         $args=array();
851         patients_dv(($selected_id ? $selected_id : FALSE), getMemberInfo(), $templateCode, $args);
852     }
853
854     
return $templateCode;
855 }
856 ?>


Gõ tìm kiếm nhanh...